package com.leetcode.leetcode2;

/**
 *  实现strStr()
 * @author: luhd
 * @create: 2021-09-12
 */
public class Practice28 {
    public static void main(String[] args) {
        String haystack = "mississippi";
        String needle = "issippi";
        System.out.println(strStr(haystack, needle));
    }
    public static int strStr(String haystack, String needle) {
        int hLen = haystack.length();
        int nLen = needle.length();
        for (int i = 0; i + nLen <= hLen; i++) {
            boolean flag = true;
            for (int j = 0; j < nLen; j++) {
                if(haystack.charAt(i+j)!=needle.charAt(j)){
                    flag = false;
                    break;
                }
            }
            if(flag) return i;
        }
        return -1;
    }
}
